package com.tt.service.impl;

import com.tt.entity.bo.EmissionLineBO;
import com.tt.entity.vo.EmissionLineVO;
import com.tt.mapper.DepartmentApparentTotalMapper;
import com.tt.service.EmissionLineService;
import com.tt.util.HandleDecimal;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * <p>
 *
 * </p>
 *
 * @version 1.0
 * @auther sugarttt
 * @since 2022-11-13 23:06:31
 */
@Service
public class EmissionLineServiceImpl implements EmissionLineService {

    private final DepartmentApparentTotalMapper departmentApparentTotalMapper;

    public EmissionLineServiceImpl(DepartmentApparentTotalMapper departmentApparentTotalMapper) {
        this.departmentApparentTotalMapper = departmentApparentTotalMapper;
    }

    @Override
    public EmissionLineVO getEmissionLine(String beginYear, String endYear, Integer provinceId) {
        EmissionLineVO emissionLineVO = new EmissionLineVO();
        ArrayList<String> years = new ArrayList<>();
        ArrayList<Double> value = new ArrayList<>();

        ArrayList<EmissionLineBO> emissionLineBOS = departmentApparentTotalMapper.getEmissionLine(beginYear, endYear, provinceId);
        Iterator<EmissionLineBO> iterator = emissionLineBOS.iterator();

        EmissionLineBO emissionLineBO;
        while (iterator.hasNext()) {
            emissionLineBO = iterator.next();

            years.add(emissionLineBO.getYear());
            value.add(HandleDecimal.handle(emissionLineBO.getValue()));
        }

        emissionLineVO.setYears(years);
        emissionLineVO.setValue(value);
        return emissionLineVO;
    }
}
